package com.nageoffer.jobtrain.judge.common.callback;

import cn.hutool.core.util.StrUtil;
import com.github.dockerjava.api.model.Frame;
import com.github.dockerjava.api.model.StreamType;
import com.github.dockerjava.core.command.ExecStartResultCallback;
import com.nageoffer.jobtrain.judge.common.enums.UserPassOjQuestionEnums;
import lombok.Data;

@Data
public class DockerStartResultCallback extends ExecStartResultCallback {
    /**
     * 记录是否通过枚举成员变量
     */
    private UserPassOjQuestionEnums userPassOjQuestionEnums;

    /**
     * 错误信息
     */
    private String errorMessage;

    /**
     * 携带信息
     */
    private String message;

    @Override
    public void onNext(Frame frame) {
        StreamType streamType = frame.getStreamType();
        if (StreamType.STDERR.equals(streamType)) {
            if (StrUtil.isEmpty(errorMessage)) {
                errorMessage = new String(frame.getPayload());
            } else {
                errorMessage = errorMessage + new String(frame.getPayload());
            }
            userPassOjQuestionEnums = UserPassOjQuestionEnums.FAILED;
        } else {
            message = new String(frame.getPayload());
            userPassOjQuestionEnums = UserPassOjQuestionEnums.PASSING;
        }
        super.onNext(frame);
    }
}